package com.zb.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.zb.dao.BaseDao;
import com.zb.dao.UserLoginDao;
import com.zb.entity.User;


public class UserLoginDaoImpl implements UserLoginDao{
	private BaseDao db=new BaseDao();
	public User getUserLogin(String uname, String userpwd) {
		String sql="select * from user where loginname=? and loginpwd=?";
		ResultSet rs=db.query(sql,uname,userpwd);
		try {
			if(rs.next()) {
				User u=new User();
				u.setLoginName(rs.getString(1));
				u.setLoginPwd(rs.getString(2));
				return u;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			db.close();
		}
		return null;
	}
	public void adduser(User u) {
		String sql ="INSERT INTO user (Name, Sex, Tel, Mail, Address, LoginName, LoginPwd) VALUES (?,?,?,?,?,?,?)";
		db.update(sql, u.getName(),u.getSex(),u.getTel(),u.getEmail(),u.getAddress(),u.getLoginName(),u.getLoginPwd());
		db.close();
	}
	
}
